package com.gaojiawei.multiThread16_JUCUtil;

import java.util.concurrent.CyclicBarrier;

/**
 *
 */
public class L02_CyclicBarrier {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(3,()->{
            System.out.println("all is ready");
        });

        new Thread(()->{
            System.out.println("one is ready");
            try {
                cyclicBarrier.await();
            } catch (Exception e) {
                System.out.println("one is absent");
                e.printStackTrace();
            } ;
            System.out.println("one go");

        }).start();

        new Thread(()->{
            System.out.println("two is ready");
            try {
                cyclicBarrier.await();
            } catch (Exception e) {
                System.out.println("two is absent");
            };
            System.out.println("two go");
        }).start();

        new Thread(()->{
            System.out.println("three is  ready");
            try {
                cyclicBarrier.await();
            } catch (Exception e) {
                System.out.println("three is absent");
            };
            System.out.println("three go");
        }).start();

    }
}
